package com.tedu.parkinglot.user.controller;

import com.tedu.parkinglot.base.response.JsonResult;
import com.tedu.parkinglot.user.pojo.dto.UserQuery;
import com.tedu.parkinglot.user.pojo.dto.UserSaveParam;
import com.tedu.parkinglot.user.pojo.vo.UserVO;
import com.tedu.parkinglot.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("select")
    public JsonResult selectUser(UserQuery userQuery){
        log.debug("查询用户:UserQuery:{}", userQuery);
        List<UserVO> list = userService.selectUser(userQuery);
        log.debug("查询结果:list={}", list);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult saveUser(UserSaveParam userSaveParam){
        log.debug("保存用户:UserSaveParam={}", userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{userId}")
    public JsonResult deleteUser(@PathVariable Long userId){
        log.debug("删除用户:id={}", userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }


}
